package com.lixinxinlove.jaychoumusic.page

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusModifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.lixinxinlove.jaychoumusic.R
import com.lixinxinlove.jaychoumusic.model.MusicModel
import com.lixinxinlove.jaychoumusic.page.util.Screen

/**
 *   author ： lixinxin
 *   time    ： 2021-12-24
 *   email：895330766@qq.com
 */
@Composable
fun MusicListScreen(navController: NavController) {

    val list =
        listOf(
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前"),
            MusicModel("爱在西元前")
        )


    Surface(modifier = Modifier.fillMaxSize()) {

        Column(
            modifier = Modifier.fillMaxSize(),
            verticalArrangement = Arrangement.Top,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            LazyColumn {
                items(list) {
                    MusicListItem(item = it, navController = navController)
                }
            }
        }
    }
}


@Composable
fun MusicListItem(item: MusicModel, navController: NavController) {

    Column(modifier = Modifier
        .fillMaxWidth()
        .clickable {
            navController.navigate(Screen.MusicPlayScreen.route)
        }) {

        Spacer(modifier = Modifier.height(8.dp))

        Row(
            modifier = Modifier.padding(start = 16.dp),
            horizontalArrangement = Arrangement.Center,
            verticalAlignment = Alignment.CenterVertically
        ) {

            Column(modifier = Modifier.weight(1f)) {
                Text(text = item.name, fontSize = 14.sp, color = Color.Black)
                Spacer(modifier = Modifier.height(4.dp))
                Text(text = item.name, fontSize = 12.sp)
            }

            Image(painter = painterResource(id = R.mipmap.ic_play), contentDescription = "播放")
            Spacer(modifier = Modifier.width(10.dp))
            Image(painter = painterResource(id = R.mipmap.ic_play), contentDescription = "播放")
            Spacer(modifier = Modifier.width(16.dp))
        }

        Spacer(modifier = Modifier.height(8.dp))
        Divider(
            Modifier
                .fillMaxWidth()
                .height(1.dp)
        )
    }
}